package fr.mywiki.business.versioning.interfaces;

import java.rmi.RemoteException;
import java.util.List;
import java.util.Map;

import javax.ejb.FinderException;

import fr.mywiki.business.entry.EntryLite;
import fr.mywiki.business.user.User;
import fr.mywiki.business.versioning.VersionLite;

/**
 * Generic instance for a version manager object.
 * 
 * @author tlombard
 */
public interface VersionManagerInterface {
	/**
	 * Returns the list of version descriptors linked to an entry, they are
	 * represented by Version objects.
	 * 
	 * @param entry
	 * @return a <code>List</code> of <code>VersionLite</code> objects.
	 */
	public List getVersions(EntryLite entry);

	/**
	 * Returns the content of the version given in parameter. This method
	 * constitutes the only way to get the content of an older version.
	 * 
	 * @param version
	 *          a <code>VersionLite</code> object
	 * @return a String object corresponding to the complete content of the
	 *         version.
	 */
	public String getVersionContent(VersionLite version) throws Exception;

	/**
	 * Adds a version to the <code>EntryLite</code> entry given in parameter.
	 * The new version is given by the <code>content</code> properties and is
	 * supposed to have been created by <code>author</code>.
	 * <p>
	 * The new current version of the entry is the one created here.
	 * 
	 * @param entry
	 *          a <code>EntryLite</code> object which is going to be linked to
	 *          this new version.
	 * @param content
	 *          the content properties of the new version.
	 * @param author
	 *          a <code>User</code> object representing the author of this
	 *          version.
	 * @return a <code>VersionLite</code> object representing the new version.
	 */
	public VersionLite addVersion(EntryLite entry, Map content, User author)
			throws Exception;

	/**
	 * Returns the current version of the entry.
	 * 
	 * @param entry
	 *          a <code>EntryLite</code> object.
	 * @return a <code>VersionLite</code> object.
	 */
	public VersionLite getCurrentVersion(EntryLite entry)
			throws RemoteException, FinderException;

	/**
	 * Returns the entry linked to the specified version.
	 * 
	 * @param version
	 *          a <code>VersionLite</code> object.
	 * @return a <code>EntryLite</code> object.
	 */
	public EntryLite getEntry(VersionLite version) throws RemoteException,
			FinderException;

	/**
	 * This method tells if the version given in parameter is the current one for
	 * the linked entry.
	 * 
	 * @param version
	 *          a <code>VersionLite</code> object.
	 * @return <tt>true</tt> if and only if the version is the current version
	 *         of the entry.
	 */
	public boolean isCurrentVersion(VersionLite version) throws RemoteException,
			FinderException;
	
	/**
   * Sets the current version of the entry linked to the version.
   * 
   * @param version
   *          a <code>VersionLite</code> object
   */
	public void setCurrentVersion(VersionLite version) throws RemoteException,
			FinderException;
	
	/**
	 * Returns the number of the version given in parameter. 1 means it is the
	 * oldests version of this entry. The greater is the number, the later the
	 * version was written.
	 * 
	 * @param version a <code>VersionLite</code> object.
	 * @return an integer between 1 and the number of versions of the entry.
	 */
	public int getVersionNumber(VersionLite version) throws RemoteException, FinderException;
}
